package com.qf.controller;

import com.qf.entity.TlGoods;
import com.qf.service.AdminGoodsService;
import com.qf.service.GoodsService;
import com.qf.utils.QiNiuTools;
import com.qf.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/AdminGoods")
public class AdminGoodsController {
    @Autowired
    AdminGoodsService adminGoodsService;
    @Autowired
    QiNiuTools qiNiuTools;
    @GetMapping("/findGoods")
    public ResultMsg findAllGoods(int page,int limit){
        return adminGoodsService.findgoods(page,limit);

    }
        @GetMapping("/findOne")
    public ResultMsg findOne(Integer gid){
        return adminGoodsService.findOneById(gid);

    }
    @PostMapping("/update")
    public ResultMsg modify(@RequestBody TlGoods goods){
         return adminGoodsService.modify(goods);
    }

    @GetMapping("/delete")
    public ResultMsg delete(int goodsId){
        return adminGoodsService.delete(goodsId);
    }

    //七牛云上传
//图片上传三要素：请求方式post/上传组件input type='file'/enctype='multipart/form-data'
    @PostMapping("/upload")
    public ResultMsg upload(MultipartFile file) {
        String upload = qiNiuTools.upload(file);
        return ResultMsg.SUCCESS(upload);
    }
}
